import request from './requests.js'
import Cookies from 'js-cookie'
import qs from "qs"
import {
	select_all_odd_url,
	select_all_odd_by_duty_url,
	select_odd_by_status_url
} from "./setting.js"

import {
	get_duty_warehouse_ship
} from './get_duty_ship.js'

import {
	Toast,
	Notify
} from 'vant'

import {
	getLocalTime
} from "./date.js"


export function get_all_odd_(callBack) {


	request({
		url: select_all_odd_url,
		method: 'get',
	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let result = response.data.resultBody.reverse()

		for (let i = 0; i < result.length; i++) {

				result[i].create_time = getLocalTime(result[i].create_time)
		

		}

		callBack(result)

	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Toast('接口请求失败，请联系管理员！')
	})



}

//get_all_odd_by duty
export function get_all_odd(callBack) {

	console.log(Cookies.get('duty_id'))

	request({
		url: select_all_odd_by_duty_url,
		method: 'post',
		data: qs.stringify({ //这里是发送给后台的数据
			duty_id: Cookies.get('duty_id')
		})
	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let result = response.data.resultBody.reverse()



		callBack(result)

	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Toast('接口请求失败，请联系管理员！')
	})



}


export function get_odd_by_status(status, page, callBack) {


	request({
		url: select_odd_by_status_url,
		method: 'get',
		params: {
			status: status,
			page: page
		}
	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let result = response.data.resultBody.reverse()

		callBack(result)

	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Toast('接口请求失败，请联系管理员！')
	})



}
